package my;

import my.mbean.web.MBeanServlet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Application {
    @Value("${sys.mbean.prefix:/mbean}")
    private String mbeanPrefix;

    public static void main(String[] args) {
        new SpringApplicationBuilder()
                .sources(Application.class)
                .run(args);
    }

    @Bean
    public ServletRegistrationBean mBeanServletRegistrationBean() {
        ServletRegistrationBean registrationBean = new ServletRegistrationBean();
        MBeanServlet mbeanServlet = new MBeanServlet();
        registrationBean.setServlet(mbeanServlet);
        registrationBean.setName("mbeanServet");
        registrationBean.addUrlMappings(mbeanPrefix + "/*");
        return registrationBean;


    }
}
